package com.gwcloud.leetcode.tags.array;

/** 
* @ClassName   : Leetcode0605 
* @author      : ganwei 
* @date        : 2020年6月18日 
* @Description : TODO 
*/
public class Leetcode0605 {
	/**
	 * -解题思路，
	 */
    public boolean canPlaceFlowers(int[] flowerbed, int n) {
        int i = 0, count = 0;
        while (i < flowerbed.length) {
            if (flowerbed[i] == 0 && (i == 0 || flowerbed[i - 1] == 0) && (i == flowerbed.length - 1 || flowerbed[i + 1] == 0)) {
                flowerbed[i] = 1;
                count++;
            }
            i++;
        }
        return count >= n;
    }
    /**
     * -主函数,
     */
    public static void main(String[] args) {
    	Leetcode0605 l0605 = new Leetcode0605();
    	int[] flowerbed = {0, 1, 0};
    	System.out.println(l0605.canPlaceFlowers(flowerbed, 1));
    }
}
